<!DOCTYPE html>
<html lang="zh">

<head>
	<meta charset="UTF-8">
	<title>数据传递</title>
	<link rel="stylesheet" href="../assets/lib/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="../assets/css/public.css" media="all">
</head>

<body>
	<div class="admin-container">
		<div class="admin-main">
			<blockquote class="layui-elem-quote">
				数据传递测试 页面A
			</blockquote>
			<div class="layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label">字符串</label>
					<div class="layui-input-block">
						<textarea class="layui-textarea" id="string">Hell World！</textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">数值</label>
					<div class="layui-input-block">
						<input type="number" class="layui-input" id="number" value="88" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">数组对象</label>
					<div class="layui-input-block">
						<textarea class="layui-textarea" id="object">{ "d": 1, "e": 3, "f": [7, 8, 9]}</textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<div class="layui-btn-group">
							<button class="layui-btn" id="send_string">传递字符串</button>
							<button class="layui-btn" id="send_number">传递数值</button>
							<button class="layui-btn" id="send_object">传递数组对象</button>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="color: red;">接收数据</label>
					<div class="layui-input-block">
						<textarea class="layui-textarea" id="receive"></textarea>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script src="../assets/lib/layui/layui.js" charset="utf-8"></script>
	<script src="../assets/js/lay-config.js" charset="utf-8"></script>
	<script type="text/javascript">
		top.transmit.receive('currency/data-1.html', function(data, obj) {
			console.log('B->A', obj.type, data);
			document.getElementById('receive').value = '';
			document.getElementById('receive').value = obj.type + '\n' + (obj.type === 'Array' || obj.type === 'Object' ? JSON.stringify(data) : data);
		});

		layui.use(['jquery', 'mTab'], function() {
			var $ = layui.jquery,
				mTab = layui.mTab;

			$('#send_string').click(function() {
				mTab.openNewTabByIframe({
					href: 'currency/data-2.html',
					title: '页面B'
				});
				top.transmit.send('currency/data-2.html', $('#string').val());
			});

			$('#send_number').click(function() {
				mTab.openNewTabByIframe({
					href: 'currency/data-2.html',
					title: '页面B'
				});
				top.transmit.send('currency/data-2.html', parseFloat($('#number').val()));
			});

			$('#send_object').click(function() {
				mTab.openNewTabByIframe({
					href: 'currency/data-2.html',
					title: '页面B'
				});
				top.transmit.send('currency/data-2.html', JSON.parse($('#object').val()));
			});
		});
	</script>
</body>

</html>